﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace RentIt06
{
    [ServiceContract(Namespace = "RentIt06", SessionMode = SessionMode.Required)]
    public interface IPublisherSession
    {

        /// <summary>
        /// Login; Starting a new session.
        /// </summary>
        /// <param name="email">The email to login with</param>
        /// <param name="password">The password</param>
        [OperationContract(IsInitiating = true, IsTerminating = false)]
        Account Login(string email, string password);

        // Read media for all access levels
        /// <summary>
        /// Exposes the media object associated with the given id.
        /// Admins and publishers with ownership over the given media, 
        /// will be able to read medias that are not published.
        /// </summary>
        /// <param name="id">The id of the media object to read.</param>
        /// <returns>The media with the given id.</returns>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        Media ReadMedia(int id);

        // Media CRUD Only for publishers/admins
        /// <summary>
        /// Create a file entry on the server.
        /// There will be nothing to download before the file has been uploaded,
        /// and the file will not be available until it is published.
        /// </summary>
        /// <returns>The ID of the media file.</returns>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        int CreateMedia();

        /// <summary>
        /// Provides an upload token for the given media file.
        /// </summary>
        /// <param name="id">The id of the media for which a file is to be uploaded.</param>
        /// <param name="hash">The hash of the file that will later be uploaded through the FileService.</param>
        /// <remarks>
        /// The token can be used in conjunction with the FileService to upload a file
        /// for the media.
        /// It is NOT possible to receive an upload token once the media has been published.
        /// The upload token will expire after 30 minutes.
        /// </remarks>
        /// <returns>The token that is to be provided to the UploadMedia operation of the FileService.</returns>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        int GetUploadToken(int id, byte[] hash);

        /// <summary>
        /// Changes the given medias data based on what has been changed in the struct.
        /// The FileName must be a string consisting of alphabetic characters, numbers, - and/or _ followed by a dot "." and some alphabetic characters or numbers.
        /// Example:
        /// To update the title and author of a media one should get the media in question f.ex. with GetMyPublishedMedia().
        /// Then change title and author with:
        ///     media.Author = "new author";
        ///     media.title  = "new title";
        /// and then update it with:
        ///     publisherSession.UpdateMedia(media);
        /// </summary>
        /// <param name="media">The media data to update</param>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        void UpdateMedia(Media media);

        /// <summary>
        /// Gives a list of medias that has been published by the account that is currently logged in.
        /// </summary>
        /// <returns>A list of Medias published by this account.</returns>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        List<Media> GetMyPublishedMedia();

        /// <summary>
        /// Make an already uploaded media available for users to see.
        /// This can be undone by calling UnPublishMedia
        /// </summary>
        /// <param name="id">The id of the media</param>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        void PublishMedia(int id);

        /// <summary>
        /// Make an published media no longer avaiable for purchase or renting
        /// The media will no longer be returned if searched for, unless you are the owner or an admin.
        /// This can be undone by calling PublishMedia
        /// </summary>
        /// <param name="id">The id of the media</param>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        void UnPublishMedia(int id);
        
        /*
        /// <summary>
        /// Delete a media and all its properties from the server.
        /// The media does not have to be published.
        /// </summary>
        /// <remarks>This method requires admin or publisher privileges</remarks>
        /// <param name="id">The id of the media</param>
        [OperationContract(IsInitiating = false, IsTerminating = false)]
        void DeleteMedia(int id);
        */

        /// <summary>
        /// Logout; Ending the session.
        /// </summary>
        [OperationContract(IsInitiating = false, IsTerminating = true)]
        void Logout();
    }
}
